package weekend01;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class List02 {
    public static void main(String[] args) {
        List<String> list  = new ArrayList<>();
        list.add("one");
        list.add("two");
        list.add("three");
        list.add("four");
        list.add("five");
        System.out.println("list:"+list);

        System.out.println("下标为2的元素为:"+list.get(2));
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }
        Iterator it = list.iterator();
        while (it.hasNext()){
            System.out.println(it.next());
        }
        for (String str : list){
            System.out.println(str);
        }

        list.set(2,"3");
        System.out.println(list);

        list.remove(0);
        System.out.println(list);

        list.add(0,"1");
        System.out.println(list);

        List<String> sublist = list.subList(2,4);
        System.out.println("sublist:"+sublist);

        for (int i = 0; i < list.size(); i++) {
            list.set(i,""+i*100);
        }
        System.out.println("list:"+list);
        System.out.println("sublist:"+sublist);

        list.remove(0);
//        System.out.println("sublist:"+sublist); 子集不支持任何操作



    }
}
